package cn.yuanqiao.web.controller.archive.storeRoom;

import cn.yuanqiao.archive.storeRoom.domain.Box;
import cn.yuanqiao.archive.storeRoom.domain.Folder;
import cn.yuanqiao.archive.storeRoom.domain.UpDownShelves;
import cn.yuanqiao.archive.storeRoom.domain.Yqda;
import cn.yuanqiao.archive.storeRoom.service.IBoxService;
import cn.yuanqiao.archive.storeRoom.service.IUpDownShelvesService;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.web.page.TableDataInfo;

import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/archive/updown")
public class UpDownShelvesController extends BaseController {

    @Autowired
    private IUpDownShelvesService upDownShelvesService;
    @Autowired
    private IBoxService boxService;

/*
    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:upDownShelves:list')")
*/
    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:upDownShelves:list')")
    public TableDataInfo list( Box box)
    {
        startPage();
        /*List<Box> list = boxService.selectBoxList(box);*/
        List<UpDownShelves> list=upDownShelvesService.getList(box);
        return getDataTable(list);
    }
    @Log(title = "下架", businessType = BusinessType.DELETE)
    @PostMapping("/offShelf")
    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:upDownShelves:downShelves')")
    public AjaxResult offShelf(@RequestBody Map map)
    {
        Boolean flag=upDownShelvesService.offShelf(map);
        if(flag){
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }
    @Log(title = "上架", businessType = BusinessType.INSERT)
    @PostMapping("/grounding")
    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:upDownShelves:upShelves')")
    public AjaxResult grounding(@RequestBody Map map){
       String flag=upDownShelvesService.grounding(map);
       if("true".equals(flag)){
           return AjaxResult.success();
       }else{
           return AjaxResult.error("上架失败,格子位置不够！");
       }
    }
    @Log(title = "调整位置", businessType = BusinessType.UPDATE)
    @PostMapping("/relocation")
    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:upDownShelves:update')")
    public AjaxResult relocation(@RequestBody Map map){
        String flag=upDownShelvesService.relocation(map);
        if("true".equals(flag)){
            return AjaxResult.success();
        }else{
            return AjaxResult.error();
        }
    }

    /**
     *按盒上架详情
     * @param
     * @return
     */
    @GetMapping(value = "/getInfo/{boxId}")
    public AjaxResult getInfo(@PathVariable("boxId") Long boxId)
    {
        return success(boxService.selectBoxByBoxId(boxId));
    }

    /**
     *按卷上架详情
     */
    @GetMapping("/detail/{folderId}")
    public AjaxResult detail(@PathVariable("folderId")Long folderId){
        Folder folder=upDownShelvesService.selectFolderById(folderId);
        return AjaxResult.success(folder);
    }

    //上下架验证
    @PostMapping("/inspectIds")
    public AjaxResult inspectIds(@RequestBody Map map){
        //验证ids
       Boolean flag=upDownShelvesService.inspectIds(map);
       if(flag) {
           return AjaxResult.success();
       }else{
           return AjaxResult.error();
       }
    }

    //打印脊盒
    @GetMapping("/printRidgeBox")
    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:upDownShelves:print')")
    public  AjaxResult printRidgeBox(String ids){
       List<Box> list=upDownShelvesService.printRidgeBox(ids);
       return AjaxResult.success(list);
    }
    //获取盒子
    @GetMapping("/position/{gridId}")
    public AjaxResult position(@PathVariable("gridId")Long gridId){
        String position=upDownShelvesService.selectPosition(gridId);
        return AjaxResult.success(position);
    }

    @GetMapping("/dalist")
    public TableDataInfo getDalist( Yqda yqda)
    {
        startPage();
        /*List<Box> list = boxService.selectBoxList(box);*/
        List<Yqda> list=upDownShelvesService.getDalist(yqda);
        return getDataTable(list);
    }

}
